<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>汉字自由联想心理分析 - 基本信息</title>
  <!-- Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>
  <!-- Font Awesome -->
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <!-- 自定义配置 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#4A6FA5',
            secondary: '#6B8EAF',
            accent: '#E76F51',
          },
        },
      }
    }
  </script>
  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .btn-hover {
        background-color: #3A5A85;
        transform: translateY(-2px);
      }
      .radio-label:hover {
        background-color: #f9fafb;
      }
    }
  </style>
</head>
<body class="bg-gray-50 min-h-screen flex flex-col">
  <div class="container mx-auto px-4 py-8 max-w-md flex-grow">
    <!-- 返回按钮 -->
    <div class="mb-8">
      <button id="back-button" class="text-primary hover:text-primary/80 transition-colors">
        <i class="fa fa-arrow-left mr-2"></i>返回
      </button>
    </div>

    <!-- 页面标题 -->
    <h1 class="text-2xl font-bold text-center text-primary mb-12">汉字自由联想心理分析</h1>

    <!-- 表单容器 -->
    <div class="bg-white rounded-xl shadow-md p-8">
      <!-- 性别选择 -->
      <div class="mb-8">
        <label class="block text-gray-700 font-medium mb-4">请选择你的性别：</label>
        <div class="space-y-3">
          <label class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer radio-label transition-colors">
            <input type="radio" name="gender" value="男" class="w-5 h-5 text-primary" checked>
            <span class="ml-3 text-gray-700">男</span>
          </label>
          <label class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer radio-label transition-colors">
            <input type="radio" name="gender" value="女" class="w-5 h-5 text-primary">
            <span class="ml-3 text-gray-700">女</span>
          </label>
          <label class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer radio-label transition-colors">
            <input type="radio" name="gender" value="其他" class="w-5 h-5 text-primary">
            <span class="ml-3 text-gray-700">其他</span>
          </label>
        </div>
      </div>

      <!-- 年龄输入 -->
      <div class="mb-12">
        <label for="age" class="block text-gray-700 font-medium mb-4">请输入你的年龄：</label>
        <div class="flex items-center">
          <input 
            type="number" 
            id="age" 
            class="flex-1 px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
            placeholder="请输入"
            min="1"
            max="120"
          >
          <span class="ml-3 text-gray-500">岁</span>
        </div>
        <p id="age-error" class="hidden text-accent text-sm mt-2">请输入有效的年龄</p>
      </div>

      <!-- 开始按钮 -->
      <button 
        id="start-button" 
        class="w-full bg-primary text-white py-4 rounded-lg font-medium transition-all hover:btn-hover disabled:opacity-50 disabled:cursor-not-allowed"
        disabled
      >
        开始
      </button>
    </div>
  </div>

  <!-- JavaScript -->
  <script>
    // 表单元素
    const ageInput = document.getElementById('age');
    const startButton = document.getElementById('start-button');
    const ageError = document.getElementById('age-error');
    const backButton = document.getElementById('back-button');
    const genderRadios = document.querySelectorAll('input[name="gender"]');

    // 返回按钮点击事件
    backButton.addEventListener('click', function() {
      window.location.href = 'index.html';
    });

    // 验证年龄输入
    ageInput.addEventListener('input', function() {
      const age = parseInt(this.value);
      if (age >= 1 && age <= 120) {
        startButton.disabled = false;
        ageError.classList.add('hidden');
      } else {
        startButton.disabled = true;
        if (this.value) {
          ageError.classList.remove('hidden');
        } else {
          ageError.classList.add('hidden');
        }
      }
    });

    // 开始按钮点击事件
    startButton.addEventListener('click', function() {
      // 获取选择的性别
      let selectedGender = '';
      genderRadios.forEach(radio => {
        if (radio.checked) {
          selectedGender = radio.value;
        }
      });
      
      // 获取输入的年龄
      const age = ageInput.value;
      
      // 保存用户信息到localStorage
      localStorage.setItem('userGender', selectedGender);
      localStorage.setItem('userAge', age);
      
      // 跳转到测试说明页面
      window.location.href = 'test-instructions.html';
    });

    // 为单选按钮标签添加点击效果
    document.querySelectorAll('.radio-label').forEach(label => {
      label.addEventListener('click', function() {
        // 移除所有标签的选中样式
        document.querySelectorAll('.radio-label').forEach(l => {
          l.classList.remove('border-primary', 'bg-blue-50');
        });
        // 为当前点击的标签添加选中样式
        this.classList.add('border-primary', 'bg-blue-50');
        // 选中对应的单选按钮
        const radio = this.querySelector('input[type="radio"]');
        radio.checked = true;
      });
    });

    // 初始化选中的单选按钮样式
    genderRadios.forEach(radio => {
      if (radio.checked) {
        const label = radio.closest('.radio-label');
        label.classList.add('border-primary', 'bg-blue-50');
      }
    });
  </script>
</body>
</html>